package com.goldman.aplt.base.type;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.goldman.http.common.s2s.model.ErrorCode;
import com.goldman.http.common.s2s.model.ResponseData;
import com.goldman.http.common.s2s.model.Status;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 业务模块均使用该响应类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class BusiResponseData<D> {

//    private BusiStatus status;
////    private D data;
//
//    public static <D> ResponseData<D> newWhenErr(String code, String ...msgs){
//        String msg = msgs != null && msgs.length > 0 ? msgs[0] : "";
//        String err = msgs != null && msgs.length > 1 ? msgs[1] : "";
//        BusiStatus status = new BusiStatus(code, msg, err);
//        ResponseData responseData = new BusiResponseData<D>(status);
//        return responseData;
//    }

    private BusiStatus status;
    private D data;

    public boolean isSuccess() {
        if (status != null && status.getCode().equals(ErrorCode.SUCCESS.getCode().toString())) {
            return true;
        }
        return false;
    }

    public boolean isError() {
        if (status != null && status.getCode().equals(ErrorCode.SUCCESS.getCode().toString())) {
            return false;
        }
        return true;
    }

    public static <D> ResponseData<D> success(D d){
        Status status = new Status(ErrorCode.SUCCESS, "");
        ResponseData responseData = new ResponseData<D>(status, d);
        return responseData;
    }

//    public static <D> ResponseData<D> failed(){
//        return newWhenErr(ErrorCode.FAILED.getCode(), ErrorCode.FAILED.getMsg(), "");
//    }
//
//    public static <D> ResponseData<D> failed(String err){
//        return newWhenErr(ErrorCode.FAILED.getCode(), ErrorCode.FAILED.getMsg(), err);
//    }
//
//    public static <D> ResponseData<D> failed(String msg, String err){
//        return newWhenErr(ErrorCode.FAILED.getCode(), msg, err);
//    }
//
//    public static <D> ResponseData<D> failed(IErrorCode errorCode, String err) {
//        return newWhenErr(errorCode.getCode(), errorCode.getMsg(), err);
//    }
//
//
//    public static <D> ResponseData<D> sysError(){
//        return newWhenErr(ErrorCode.SYS_ERROR.getCode(), ErrorCode.SYS_ERROR.getMsg(), "");
//    }
//
//    public static <D> ResponseData<D> sysError(String err){
//        return newWhenErr(ErrorCode.SYS_ERROR.getCode(), ErrorCode.SYS_ERROR.getMsg(), err);
//    }
//
//    public static <D> ResponseData<D> sysError(String msg, String err){
//        return newWhenErr(ErrorCode.SYS_ERROR.getCode(), msg, err);
//    }
//
//
//    public static <D> ResponseData<D> argError(){
//        return newWhenErr(ErrorCode.ARG_ERROR.getCode(), ErrorCode.ARG_ERROR.getMsg(), "");
//    }
//
//    public static <D> ResponseData<D> argError(String err){
//        return newWhenErr(ErrorCode.ARG_ERROR.getCode(), ErrorCode.ARG_ERROR.getMsg(), err);
//    }
//
//    public static <D> ResponseData<D> argError(String msg, String err){
//        return newWhenErr(ErrorCode.ARG_ERROR.getCode(), msg, err);
//    }

    public static <D> BusiResponseData<D> newWhenErr(String code, String ...msgs){
        String msg = msgs != null && msgs.length > 0 ? msgs[0] : "";
        String err = msgs != null && msgs.length > 1 ? msgs[1] : "";
        BusiStatus status = new BusiStatus(code, msg, err);
        BusiResponseData responseData = new BusiResponseData<D>(status, null);
        return responseData;
    }

//    public static <D> ResponseData<D> newWhenErr(Status status){
//        Status newStatus = new Status(status.getCode(), status.getMsg(), status.getErr());
//        ResponseData responseData = new ResponseData<D>(newStatus, null);
//        return responseData;
//    }
}
